package demo.practice.top100;

public class P55_2 {

    public static void main(String[] args) {
        P55_2 p55_2 = new P55_2();
        p55_2.canJump(new int[]{2,3,1,1,4});
    }

    public boolean canJump(int[] nums) {
        if (nums == null || nums.length < 2) {
            return true;
        }


        boolean[] jps = new boolean[nums.length ];
        jps[0] = true;

        for (int i = 0; i < nums.length; i++) {
            if (!jps[i])
                return false;

            int steps = nums[i];
            int maxRange = steps + i;
            if (maxRange >= nums.length - 1) {
                return true;
            }


            if (jps[maxRange]) {
                continue;
            }

            for (int j = i + 1; j <= maxRange; j++) {
                jps[j] = true;
            }
        }
        return false;
    }


}
